#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "person.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    person = new Person(this); // 创建Person对象，并设置为MainWindow的子对象。
    person->setName("John Doe"); // 设置属性值。
    person->setAge(30); // 设置属性值。
    qDebug() << "Name:" << person->name() << ", Age:" << person->age();

    connect(person, SIGNAL(nameChanged(QString)), this, SLOT(showNameChanged(QString)));
    connect(person, SIGNAL(ageChanged(int)), this,SLOT(showAgeChanged(int)));
}

MainWindow::~MainWindow()
{
    delete person;
    delete ui;
}

void MainWindow::showNameChanged(const QString&  name)
{
    qDebug() <<"Name Address:"<< &name;
    qDebug() << "Name:" << name;
}

void MainWindow::showAgeChanged(int age)
{
    qDebug() << " Age:" << person->age();
}

void MainWindow::on_pushButton_clicked()
{
    QString tmpName = ui->plainTextEdit->toPlainText();
    qDebug() <<"tmpName Address:"<< &tmpName;
    person->setName(tmpName);
}
